﻿using MediatR;
using SCM.API.Read.Application.Command.Sale;
using SCM.Domain;
using SCM.ErrorCode;
using SCM.Infrastructure.Implement;

namespace SCM.API.Read.Application.Handler.Sale
{
    public class FanSaleHandler : IRequestHandler<FanSaleCommand, APIResult<SaleManagementModel>>
    {
        DatabaseContext db;

        public FanSaleHandler(DatabaseContext db)
        {
            this.db = db;
        }
        public Task<APIResult<SaleManagementModel>> Handle(FanSaleCommand request, CancellationToken cancellationToken)
        {
            APIResult<SaleManagementModel> res = new APIResult<SaleManagementModel>();
            var purchase = db.SqlSugar.Queryable<SaleManagementModel>().Where(s => s.Id == request.Id && s.IsDel == false).First();
            if (purchase == null)
            {
                res.Code = APIEnum.Fail;
                res.Msg = "不存在";
                return Task.FromResult(res);
            }
            res.Code = APIEnum.Success;
            res.Data = purchase;
            return Task.FromResult(res);
        }
    }
}
